package com.gcmm.utils;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import static java.lang.Thread.sleep;

public class FileUtils {

    //复制path目录下所有文件内容到outPath文件中
    public static void copyAllContentToFile( String inPath,String outPath) {

        File outFile = new File(outPath);
        List<File> files = FileUtil.loopFiles(inPath);
        System.out.println("inPath:"+inPath+" outPath:"+outPath);
        //覆盖目标文件： FileUtil.writeLines(List.of(""),outFile,"utf-8",false);
        for (File file : files) {

            System.out.println( file.getName());

            List<String> lines = FileUtil.readLines(file, "utf-8");
            lines.forEach(System.out::println);
            //写一个将内容输出到文件的方法

            FileUtil.writeLines(lines,outFile,"UTF-8",true);
        }
    }

    //获得path目录所有文件名
    public static List<String> getAllFileNames(String path){
        //  List<File> files = FileUtil.loopFiles(path);
        return FileUtil.loopFiles(path).stream().map(File::getName).toList();


    }
//删除path目录下所有文件名包含name的文件
    public static void deleteFileByLikeName(String path,String name){

        Arrays.stream(FileUtil.ls(path)).filter(file -> file.getName().contains(name)&&file.isFile())
                .forEach(File::delete);


    }



}
